﻿using System.Text;
using System.Windows;
using System.Windows.Controls;
using WPFExcelReport.Helpers;
namespace WPFExcelReport.Controls
{ 
	/// <summary>
	/// A control that shows a loading animation.
	/// </summary>
	public class AutoTrimTextBox:TextBox
	{  
        public AutoTrimTextBox()
        {
          
        }
        protected override void OnGotFocus(RoutedEventArgs e)
        {
            base.OnGotFocus(e);
            if (this.MaxLength > 0)
            {
                Text = Text.Trim();
            }
        }
        protected override void OnTextInput(System.Windows.Input.TextCompositionEventArgs e)
        { 
            if (this.MaxLength > 0)
            {
                Text = Text.Trim();
            }
            base.OnTextInput(e);
        }
        protected override void OnLostFocus(RoutedEventArgs e)
        {
            
            if (this.MaxLength > 0)
            {
                Text = Helper.Left(Text.Trim().PadRight(MaxLength), MaxLength);
            }
            base.OnLostFocus(e);
        }
	}
}
